#ifndef TRANSITLINK_H_
#define TRANSITLINK_H_

#include <e32base.h>
#include <http\RHTTPTransaction.h>
#include <http\RHTTPSession.h>
#include <http\RHTTPHeaders.h>
#include <http\MHTTPTransactionCallback.h>
#include <http\MHTTPDataSupplier.h>

struct TTransitLinkCell
{
	TInt iLinesBeg;
	TInt iLinesEnd;
};

struct TTransitLinkLine
	{
	TPtrC8 iText;
	enum TShortcutType { SHORTCUT_NONE, SHORTCUT_BUSSTOP, SHORTCUT_BUSSERVICE } iShortcutType;
	TPtrC8 iShortcut;
	};

struct MTransitLinkCallbackPtjp
	{
	virtual void MTransitLinkCallbackPtjpRunL(const TDesC8& aStopStart, const TDesC8& aStopEnd, TInt aStatus, TInt aLastError, TInt aStatusCode, TInt aTableIndex, TInt aRowIndex, const RArray<TTransitLinkCell>& aRow, const RArray<TTransitLinkLine>& aLines) = 0;
	};
class CTransitLinkRequestPtjp : public CBase, public MHTTPTransactionCallback, public MHTTPDataSupplier
	{
private:
	enum { PHASE1, PHASE2 } iPhase;
	HBufC8* iStopStart;
	HBufC8* iStopEnd;
	HBufC8* iRouteType;
	RBuf8 iBody;
	MTransitLinkCallbackPtjp* iTarget;
	RHTTPTransaction iTransaction;
	RHTTPSession* iSession;
	TBool iTransactionSubmitted;
	TInt iLastError;
	RBuf8 iPostData;
	
	RBuf8 iMrtStart, iMrtStartDetail, iMrtStartDist;
	RBuf8 iMrtEnd, iMrtEndDetail, iMrtEndDist;
	
	void ConstructL();
public:
    virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
    virtual void MHFRunL_PHASE1(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
    virtual void MHFRunL_PHASE2(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
    virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
	void SubmitL(RHTTPSession& aSession, const TDesC8& aStopStart, const TDesC8& aStopEnd, const TDesC8& aRouteType, MTransitLinkCallbackPtjp* aTarget);
	void SubmitL_PHASE1();
	void SubmitL_PHASE2();
	TBool RequestPending() const;
	void Cancel();
	virtual TBool GetNextDataPart(TPtrC8& aDataPart);
	virtual TInt OverallDataSize();
	virtual void ReleaseData();
	virtual TInt Reset();
	static CTransitLinkRequestPtjp* NewLC();
	static CTransitLinkRequestPtjp* NewL();
	virtual ~CTransitLinkRequestPtjp();
	static HBufC8* LineToTextLC(const TDesC8& aString);
	};


#endif /* TRANSITLINK_H_ */
